{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用企业公示网做例子\n",
    "\n",
    "获取gt和challenge两个参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 企业公示网做例子\n",
    "index_url = 'http://www.gsxt.gov.cn/index.html'\n",
    "index_header= {\n",
    "            'accept': \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\",\n",
    "            'accept-encoding': \"gzip, deflate\",\n",
    "            'accept-language': \"zh-CN,zh;q=0.9\",\n",
    "            'connection': \"keep-alive\",\n",
    "            'host': \"www.gsxt.gov.cn\",\n",
    "            'upgrade-insecure-requests': \"1\",\n",
    "            'Referer': 'http://www.gsxt.gov.cn/index.html',\n",
    "            \"User-Agent\": \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36\",\n",
    "        }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 代理手动配置，避免本地的IP被封了\n",
    "proxy = {\n",
    "        \"https\": \"https://\" + \"60.188.9.176:3000\",\n",
    "        # \"http\": \"http://\" + \"60.167.135.237:8118\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = requests.get(index_url, headers=index_header, proxies=proxy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "获取到第一段JS代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'<script>var x=\"firstChild@setTimeout@toString@0xEDB88320@createElement@06@String@if@3@Wed@new@toLowerCase@@e@@search@@@replace@G@@length@Expires@@try@rOm9XFMtA3QKV7nYsPGT4lifyWwkq5vcjH2IdxUoCbhERLaz81DNB6@JgSe0upZ@@@innerHTML@@pathname@RegExp@@challenge@onreadystatechange@match@@@@2@F@fromCharCode@reverse@a@1589364371@@cookie@attachEvent@@captcha@function@eval@while@@return@chars@var@href@else@@@@f@location@Array@https@charCodeAt@@D@substr@1@@1500@DOMContentLoaded@false@13@@@Path@@@@@addEventListener@parseInt@split@S@document@g@@36@@@8@0xFF@@d@WO@@20@@@@May@0@@@@@join@11@for@Hkav@@charAt@@@@GMT@__jsl_clearance@438@catch@@@window@div@\".replace(/@*$/,\"\").split(\"@\"),y=\"1q 1v=1k(){2(\\'21.1r=21.10+21.g.j(/[\\\\\\\\?|&]1j-13/,\\\\\\\\\\'\\\\\\\\\\')\\',2a);2p.1g=\\'3p=1e.3q|3a|\\'+(1k(){1q 1t=[1k(1v){1o 1v},1k(1t){1o 1t},1k(1v){1o 1l(\\'7.1b(\\'+1v+\\')\\')},1k(1v){3h(1q 1t=3a;1t<1v.m;1t++){1v[1t]=2m(1v[1t]).3(2s)};1o 1v.3f(\\'\\')}],1v=[[[(-~~~\\'\\'+[-~-~~~\\'\\']>>-~-~~~\\'\\')]+[-~-~~~\\'\\'+((-~{}<<-~{})^-~~~\\'\\')]],\\'2o\\',[[((-~{}<<-~{})^-~~~\\'\\')-~~~\\'\\'-~!{}+((-~{}<<-~{})^-~~~\\'\\')]+[-~[-~-~~~\\'\\'-~-~~~\\'\\'-~-~~~\\'\\']]],\\'32\\',[[((-~{}<<-~{})^-~~~\\'\\')-~~~\\'\\'-~!{}+((-~{}<<-~{})^-~~~\\'\\')]+(-~[]-~[]+[[]][3a])],\\'1a\\',[[(-~~~\\'\\'+[-~-~~~\\'\\']>>-~-~~~\\'\\')]+[-~-~~~\\'\\'+((-~{}<<-~{})^-~~~\\'\\')]],[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~\\'\\'))],\\'3i\\',[[(-~~~\\'\\'+[-~-~~~\\'\\']>>-~-~~~\\'\\')]+[~~[]]],\\'k\\',[((-~{}<<-~{})^-~~~\\'\\')-~~~\\'\\'-~!{}+((-~{}<<-~{})^-~~~\\'\\')],\\'26\\',[[-~{}]+[-~[-~-~~~\\'\\'-~-~~~\\'\\'-~-~~~\\'\\']]],[[-~[-~-~~~\\'\\'-~-~~~\\'\\'-~-~~~\\'\\']]+[((-~{}<<-~{})<<-~{})]],[(-~[]-~[]+[[]][3a])+[(-~~~\\'\\'+[-~-~~~\\'\\']>>-~-~~~\\'\\')],[(-~~~\\'\\'+[-~-~~~\\'\\']>>-~-~~~\\'\\')]+[(-~~~\\'\\'+[-~-~~~\\'\\']>>-~-~~~\\'\\')]],[[-~[-~-~~~\\'\\'-~-~~~\\'\\'-~-~~~\\'\\']]+(-~[]-~[]+[[]][3a])],[(-~[]-~[]+[[]][3a])+(-~!{}+(-~[]-~[]<<-~[]-~[])+[]+[[]][3a])],\\'33\\',[[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~\\'\\'))]+[-~-~~~\\'\\'+((-~{}<<-~{})^-~~~\\'\\')]],[[(-~~~\\'\\'+[-~-~~~\\'\\']>>-~-~~~\\'\\')]+[((-~{}<<-~{})<<-~{})]],[[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~\\'\\'))]+(-~!{}+(-~[]-~[]<<-~[]-~[])+[]+[[]][3a])],\\'%\\',[(-~~~\\'\\'+[-~-~~~\\'\\']>>-~-~~~\\'\\')],\\'26\\'];3h(1q t=3a;t<1v.m;t++){1v[t]=1t[[9,28,19,28,19,28,9,3a,28,9,28,3a,28,9,19,9,19,9,28,19,9,19,28,3a,28][t]](1v[t])};1o 1v.3f(\\'\\')})()+\\';n=a, 2d-39-35 3g:6:3g 3o;2g=/;\\'};8((1k(){p{1o !!3u.2l;}3r(e){1o 2c;}})()){2p.2l(\\'2b\\',1v,2c)}1s{2p.1h(\\'14\\',1v)}\",f=function(x,y){var a=0,b=0,c=0;x=x.split(\"\");y=y||99;while((a=x.shift())&&(b=a.charCodeAt(0)-77.5))c=(Math.abs(b)<13?(b+48.5):parseInt(a,36))+y*c;return c},z=f(y.match(/\\\\w/g).sort(function(x,y){return f(x)-f(y)}).pop());while(z++)try{eval(y.replace(/\\\\b\\\\w+\\\\b/g, function(y){return x[f(y,z)-1]||(\"_\"+y)}));break}catch(_){}</script>\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\n'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.text    # 获取第一段js"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "获取jsluid参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3873563fb2bec146ee50d1146cda3483'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jsluid = response.headers['Set-Cookie'].split('=')[1].split(';')[0]    \n",
    "jsluid"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "解密出第二段js代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"var _1v=function(){setTimeout('location.href=location.pathname+location.search.replace(/[\\\\\\\\?|&]captcha-challenge/,\\\\\\\\'\\\\\\\\')',1500);document.cookie='__jsl_clearance=1589364371.438|0|'+(function(){var _1t=[function(_1v){return _1v},function(_1t){return _1t},function(_1v){return eval('String.fromCharCode('+_1v+')')},function(_1v){for(var _1t=0;_1t<_1v.length;_1t++){_1v[_1t]=parseInt(_1v[_1t]).toString(36)};return _1v.join('')}],_1v=[[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[-~-~~~''+((-~{}<<-~{})^-~~~'')]],'S',[[((-~{}<<-~{})^-~~~'')-~~~''-~!{}+((-~{}<<-~{})^-~~~'')]+[-~[-~-~~~''-~-~~~''-~-~~~'']]],'d',[[((-~{}<<-~{})^-~~~'')-~~~''-~!{}+((-~{}<<-~{})^-~~~'')]+(-~[]-~[]+[[]][0])],'F',[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[-~-~~~''+((-~{}<<-~{})^-~~~'')]],[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~''))],'Hkav',[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[~~[]]],'G',[((-~{}<<-~{})^-~~~'')-~~~''-~!{}+((-~{}<<-~{})^-~~~'')],'D',[[-~{}]+[-~[-~-~~~''-~-~~~''-~-~~~'']]],[[-~[-~-~~~''-~-~~~''-~-~~~'']]+[((-~{}<<-~{})<<-~{})]],[(-~[]-~[]+[[]][0])+[(-~~~''+[-~-~~~'']>>-~-~~~'')],[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[(-~~~''+[-~-~~~'']>>-~-~~~'')]],[[-~[-~-~~~''-~-~~~''-~-~~~'']]+(-~[]-~[]+[[]][0])],[(-~[]-~[]+[[]][0])+(-~!{}+(-~[]-~[]<<-~[]-~[])+[]+[[]][0])],'WO',[[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~''))]+[-~-~~~''+((-~{}<<-~{})^-~~~'')]],[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[((-~{}<<-~{})<<-~{})]],[[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~''))]+(-~!{}+(-~[]-~[]<<-~[]-~[])+[]+[[]][0])],'%',[(-~~~''+[-~-~~~'']>>-~-~~~'')],'D'];for(var _t=0;_t<_1v.length;_t++){_1v[_t]=_1t[[3,1,2,1,2,1,3,0,1,3,1,0,1,3,2,3,2,3,1,2,3,2,1,0,1][_t]](_1v[_t])};return _1v.join('')})()+';Expires=Wed, 13-May-20 11:06:11 GMT;Path=/;'};if((function(){try{return !!window.addEventListener;}catch(e){return false;}})()){document.addEventListener('DOMContentLoaded',_1v,false)}else{document.attachEvent('onreadystatechange',_1v)}\""
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import re\n",
    "import execjs\n",
    "\n",
    "\n",
    "des_js = 'function get_z(x, y) {\\n    f = function (x, y) {\\n        var a = 0,\\n            b = 0,\\n            c = 0;\\n        x = x.split(\"\");\\n        y = y || 99;\\n        while ((a = x.shift()) && (b = a.charCodeAt(0) - 77.5)) c = (Math.abs(b) < 13 ? (b + 48.5) : parseInt(a, 36)) + y * c;\\n        return c\\n    };\\n    x = x.replace(/@*$/, \"\").split(\"@\");\\n    z = f(y.match(/\\\\w/g).sort(function (x, y) {\\n        return f(x) - f(y)\\n    }).pop());\\n    return [x, y, z]\\n\\n}\\n\\nfunction get_js(x, y, z) {\\n    f = function (x, y) {\\n        var a = 0,\\n            b = 0,\\n            c = 0;\\n        x = x.split(\"\");\\n        y = y || 99;\\n        while ((a = x.shift()) && (b = a.charCodeAt(0) - 77.5)) c = (Math.abs(b) < 13 ? (b + 48.5) : parseInt(a, 36)) + y * c;\\n        return c\\n    };\\n    x = eval(x);\\n    z = z + 1;\\n    p = y.replace(/\\\\b\\\\w+\\\\b/g,\\n        function (y) {\\n            return x[f(y, z) - 1] || (\"_\" + y)\\n        });\\n    return p\\n\\n}\\n\\n\\nfunction once_js(x, y) {\\n    f = function (x, y) {\\n        var a = 0,\\n            b = 0,\\n            c = 0;\\n        x = x.split(\"\");\\n        y = y || 99;\\n        while ((a = x.shift()) && (b = a.charCodeAt(0) - 77.5)) c = (Math.abs(b) < 13 ? (b + 48.5) : parseInt(a, 36)) + y * c;\\n        return c\\n    },\\n        x = x.replace(/@*$/, \"\").split(\"@\");\\n    z = f(y.match(/\\\\w/g).sort(function (x, y) {\\n        return f(x) - f(y)\\n    }).pop());\\n    while (z++) try {\\n        g = y.replace(/\\\\b\\\\w+\\\\b/g,\\n            function (y) {\\n                return x[f(y, z) - 1] || (\"_\" + y)\\n            });\\n        return g\\n    } catch (_) {\\n    }\\n}'\n",
    "des_js = execjs.compile(des_js)\n",
    "first_js = response.text\n",
    "x = re.findall('var x=\"(.*?)\"', first_js)[0]\n",
    "y = re.findall(',y=\"(.*?)\"', first_js)[0]\n",
    "second_js = des_js.call('once_js', x, y)\n",
    "second_js"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "处理第二段js，去除document"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"cookie='__jsl_clearance=1589364371.438|0|'+(function(){var _1t=[function(_1v){return _1v},function(_1t){return _1t},function(_1v){return eval('String.fromCharCode('+_1v+')')},function(_1v){for(var _1t=0;_1t<_1v.length;_1t++){_1v[_1t]=parseInt(_1v[_1t]).toString(36)};return _1v.join('')}],_1v=[[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[-~-~~~''+((-~{}<<-~{})^-~~~'')]],'S',[[((-~{}<<-~{})^-~~~'')-~~~''-~!{}+((-~{}<<-~{})^-~~~'')]+[-~[-~-~~~''-~-~~~''-~-~~~'']]],'d',[[((-~{}<<-~{})^-~~~'')-~~~''-~!{}+((-~{}<<-~{})^-~~~'')]+(-~[]-~[]+[[]][0])],'F',[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[-~-~~~''+((-~{}<<-~{})^-~~~'')]],[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~''))],'Hkav',[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[~~[]]],'G',[((-~{}<<-~{})^-~~~'')-~~~''-~!{}+((-~{}<<-~{})^-~~~'')],'D',[[-~{}]+[-~[-~-~~~''-~-~~~''-~-~~~'']]],[[-~[-~-~~~''-~-~~~''-~-~~~'']]+[((-~{}<<-~{})<<-~{})]],[(-~[]-~[]+[[]][0])+[(-~~~''+[-~-~~~'']>>-~-~~~'')],[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[(-~~~''+[-~-~~~'']>>-~-~~~'')]],[[-~[-~-~~~''-~-~~~''-~-~~~'']]+(-~[]-~[]+[[]][0])],[(-~[]-~[]+[[]][0])+(-~!{}+(-~[]-~[]<<-~[]-~[])+[]+[[]][0])],'WO',[[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~''))]+[-~-~~~''+((-~{}<<-~{})^-~~~'')]],[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[((-~{}<<-~{})<<-~{})]],[[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~''))]+(-~!{}+(-~[]-~[]<<-~[]-~[])+[]+[[]][0])],'%',[(-~~~''+[-~-~~~'']>>-~-~~~'')],'D'];for(var _t=0;_t<_1v.length;_t++){_1v[_t]=_1t[[3,1,2,1,2,1,3,0,1,3,1,0,1,3,2,3,2,3,1,2,3,2,1,0,1][_t]](_1v[_t])};return _1v.join('')})()+';Expires=Wed, 13-May-20 11:06:11 '\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_js = second_js.replace('\\\\\\\\', '\\\\')\n",
    "\n",
    "new_js = 'cookie' + new_js.split('document.cookie')[1]\n",
    "new_js = new_js.split('GMT;Path=/;')[0] + \"'\"\n",
    "\n",
    "if re.findall(\"(var .{0,5}=)document\\.createElement\\('div'\\);\", new_js):\n",
    "        _3d = re.findall(\"(var .{0,5}=)document\\.createElement\\('div'\\);\", new_js)\n",
    "        _2b = re.findall(\"(var .{0,5}=).{0,5}\\.match\\(/https\\?:\\\\\\/\\\\\\//\\)\\[0\\];\", new_js)\n",
    "        new_js = re.sub(\n",
    "            \"var .{0,5}=document\\.createElement\\('div'\\);\", \n",
    "            _3d[0] + f'\"{index_url.replace(\"http://\", \"\")}\";',\n",
    "            new_js\n",
    "        )\n",
    "        new_js = re.sub(\"_.{0,5}\\.innerHTML='<a href=.{0,25}</a>';\", \"\", new_js)\n",
    "        new_js = re.sub(\"_.{0,5}=.{0,5}\\.firstChild\\.href;\", \"\", new_js)\n",
    "        new_js = re.sub(\"var .{0,5}=.{0,5}\\.match\\(/https\\?:\\\\\\/\\\\\\//\\)\\[0\\];\", _2b[0] + '\"http://\";', new_js)\n",
    "        new_js = re.sub(\"_.{0,5}=.{0,5}\\.substr\\(.{0,5}\\.length\\)\\.toLowerCase\\(\\);\", \"\", new_js)\n",
    "new_js"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "处理js，去除Window"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "find = re.findall(\"!*window\\[.*?\\]\", new_js)\n",
    "if find:\n",
    "    for f in find:\n",
    "        if '!' in f:\n",
    "            if len(re.findall('!', f)) % 2 == 0:\n",
    "                new_js = new_js.replace(f, 'false')\n",
    "            else:\n",
    "                new_js = new_js.replace(f, 'true')\n",
    "        else:\n",
    "            new_js = new_js.replace(f, 'undefined')\n",
    "new_js = new_js.replace('window.headless', 'undefined')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"cookie='__jsl_clearance=1589364371.438|0|'+(function(){var _1t=[function(_1v){return _1v},function(_1t){return _1t},function(_1v){return eval('String.fromCharCode('+_1v+')')},function(_1v){for(var _1t=0;_1t<_1v.length;_1t++){_1v[_1t]=parseInt(_1v[_1t]).toString(36)};return _1v.join('')}],_1v=[[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[-~-~~~''+((-~{}<<-~{})^-~~~'')]],'S',[[((-~{}<<-~{})^-~~~'')-~~~''-~!{}+((-~{}<<-~{})^-~~~'')]+[-~[-~-~~~''-~-~~~''-~-~~~'']]],'d',[[((-~{}<<-~{})^-~~~'')-~~~''-~!{}+((-~{}<<-~{})^-~~~'')]+(-~[]-~[]+[[]][0])],'F',[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[-~-~~~''+((-~{}<<-~{})^-~~~'')]],[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~''))],'Hkav',[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[~~[]]],'G',[((-~{}<<-~{})^-~~~'')-~~~''-~!{}+((-~{}<<-~{})^-~~~'')],'D',[[-~{}]+[-~[-~-~~~''-~-~~~''-~-~~~'']]],[[-~[-~-~~~''-~-~~~''-~-~~~'']]+[((-~{}<<-~{})<<-~{})]],[(-~[]-~[]+[[]][0])+[(-~~~''+[-~-~~~'']>>-~-~~~'')],[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[(-~~~''+[-~-~~~'']>>-~-~~~'')]],[[-~[-~-~~~''-~-~~~''-~-~~~'']]+(-~[]-~[]+[[]][0])],[(-~[]-~[]+[[]][0])+(-~!{}+(-~[]-~[]<<-~[]-~[])+[]+[[]][0])],'WO',[[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~''))]+[-~-~~~''+((-~{}<<-~{})^-~~~'')]],[[(-~~~''+[-~-~~~'']>>-~-~~~'')]+[((-~{}<<-~{})<<-~{})]],[[[(-~{}<<-~{})]*(((-~{}<<-~{})^-~~~''))]+(-~!{}+(-~[]-~[]<<-~[]-~[])+[]+[[]][0])],'%',[(-~~~''+[-~-~~~'']>>-~-~~~'')],'D'];for(var _t=0;_t<_1v.length;_t++){_1v[_t]=_1t[[3,1,2,1,2,1,3,0,1,3,1,0,1,3,2,3,2,3,1,2,3,2,1,0,1][_t]](_1v[_t])};return _1v.join('')})()+';Expires=Wed, 13-May-20 11:06:11 '\""
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_js"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "获取jsl_clearance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1589364371.438|0|zSWdRFz6HkavuG8DhJnxHtWOAyE%3D'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "js = \"\"\"\n",
    "        function getJS() {\n",
    "        %s\n",
    "        return cookie\n",
    "        }\n",
    "    \"\"\" % new_js\n",
    "exec_js = execjs.compile(js)\n",
    "jsl = exec_js.call('getJS')\n",
    "jsl = jsl.split(';')[0]\n",
    "jsl_clearance = jsl.split('=')[1]\n",
    "jsl_clearance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'8E11E8556264D5431C97B28A64F213DA-n2:-1'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取第一个jessionid\n",
    "headers = index_header.copy()\n",
    "headers['Cookie'] = f'__jsluid_h={jsluid}; __jsl_clearance={jsl_clearance};'\n",
    "response2 = requests.get(index_url, headers=headers, proxies=proxy)\n",
    "JSESSIONID1 = re.findall('JSESSIONID=(.*?);', response2.headers['Set-Cookie'])[0]\n",
    "JSESSIONID1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'8E11E8556264D5431C97B28A64F213DA-n2:0'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取第二个jessionid\n",
    "import time\n",
    "\n",
    "url = 'http://www.gsxt.gov.cn/SearchItemCaptcha?t=' + str(int(time.time()*1000))\n",
    "headers = index_header.copy()\n",
    "headers['Cookie'] = f'__jsluid_h={jsluid}; __jsl_clearance={jsl_clearance};JSESSIONID={JSESSIONID1}'\n",
    "response3 = requests.get(url, headers=headers, proxies=proxy)\n",
    "JSESSIONID2 = re.findall('JSESSIONID=(.*?);', response3.headers['Set-Cookie'])[0]\n",
    "JSESSIONID2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "测试cookie，如果状态码是200，获取gt和challenge"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import json\n",
    "\n",
    "headers = index_header.copy()\n",
    "headers['Cookie'] = f'__jsluid_h={jsluid}; __jsl_clearance={jsl_clearance};JSESSIONID={JSESSIONID2}'\n",
    "url = 'http://www.gsxt.gov.cn/SearchItemCaptcha?t=' + str(int(time.time()*1000))\n",
    "response4 = requests.get(url, headers=headers, proxies=proxy)\n",
    "response4.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "gt_challenge_json = json.loads(response4.text)\n",
    "gt = gt_challenge_json['gt']\n",
    "challenge = gt_challenge_json['challenge']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'62756445cd524543f5a16418cd920ffd'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'8a7c7f8b5b53a72f95d50b9181c758e6'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "challenge"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 下面开始搜索企业信息"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 如果您看到这里，请给我一个star，谢谢，如有遗漏，请留言指正，感激！"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里先走一遍采集流程，本地打码服务的实现稍后整理，要先整理完模型训练部分才能打码\n",
    "服务实现流程：\n",
    "1. 拿到gt和challenge获取验证码，验证码有两种\n",
    "    - 滑动3.0\n",
    "    - 文字点选，这部分的训练模型已经开源了，移步首页\n",
    "2. 破解验证码，获取validate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 本地打码服务器，所有验证码类型在这里统一处理，返回validate即可\n",
    "get_valid_server = 'http://127.0.0.1:5051'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "url = f'{get_valid_server}/geetest?gt={gt}&challenge={challenge}'\n",
    "resp = requests.get(url)\n",
    "resp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'data': {'challenge': '8a7c7f8b5b53a72f95d50b9181c758e6',\n",
       "  'result': 'success',\n",
       "  'validate': 'fba9455b230064c63164bb06f453f52e'},\n",
       " 'status': 'success'}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val_resu = json.loads(resp.text)\n",
    "\n",
    "val_resu"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "成功获取validate，开始进行搜索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "from lxml.etree import _Element\n",
    "from lxml import etree\n",
    "\n",
    "def parse_list(content):\n",
    "    def try_catch(data, patten):\n",
    "        if isinstance(data, _Element):\n",
    "            try:\n",
    "                target = re.sub('\\s', '', data.xpath(patten)[0].strip())\n",
    "            except:\n",
    "                target = None\n",
    "            return target\n",
    "        return data\n",
    "    a_list = []\n",
    "    content_list = content\n",
    "    html = etree.HTML(content_list)\n",
    "    list_len = int(html.xpath('//span[@class=\"search_result_span1\"]/text()')[0])\n",
    "    if list_len == 0:\n",
    "        return 'None'\n",
    "    else:\n",
    "        targit_len = 1\n",
    "    for i in range(1, targit_len + 1):\n",
    "        try:\n",
    "            url = html.xpath('//div[@class=\"main-layout fw f14\"]/div[2]/a[' + str(i) + ']/@href')[0]\n",
    "            href = 'http://www.gsxt.gov.cn{}'.format(url)\n",
    "        except:\n",
    "            href = None\n",
    "        dic = {\n",
    "            'href': href\n",
    "        }\n",
    "        a_list.append(dic)\n",
    "    return a_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "def list_page(val_resu, jsluid, jsl_clearance, JSESSIONID, search_word):\n",
    "    time.sleep(1)\n",
    "    validate = val_resu['data']['validate']\n",
    "    chall = val_resu['data']['challenge']\n",
    "    data = {\n",
    "        'tab': 'ent_tab',\n",
    "        'province': '',\n",
    "        'geetest_challenge': chall,\n",
    "        'geetest_validate': validate,\n",
    "        'geetest_seccode': '{}|jordan'.format(validate),\n",
    "        'token': '57571798',\n",
    "        'searchword': f'{search_word}',\n",
    "    }\n",
    "    time.sleep(5)\n",
    "    headers =index_header.copy()\n",
    "    headers['Cookie'] = f'__jsluid_h={jsluid}; __jsl_clearance={jsl_clearance};JSESSIONID={JSESSIONID}'\n",
    "    post_url = 'http://www.gsxt.gov.cn/corp-query-search-1.html'\n",
    "    content = requests.post(url=post_url, data=data, headers=headers, verify=False, timeout=(60, 60), proxies=proxy)\n",
    "    if content.status_code == 200:\n",
    "        if '您的IP地址' in content.text:\n",
    "            print('请更换代理')\n",
    "        else:\n",
    "            return content.text\n",
    "    else:\n",
    "        print('cookies失效')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "配置要搜索的关键词"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "search_word = \"百度\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "if val_resu['data']['result'] == 'fail':\n",
    "    print('get valid error')\n",
    "else:\n",
    "    content_text = list_page(val_resu, jsluid, jsl_clearance, JSESSIONID2, search_word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "href = parse_list(content_text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'href': 'http://www.gsxt.gov.cn/%7BC132146AA913B5B85A24D3698BCF37F48AE6B456EC80C4B6902AE997FB525D23D4B8FC8EA812404D51929F83D12674CE8B7534DAFFFB498F8BCA2CEAEEE4298329BF29BF29CF7DB57DEBF41294709611BD80320BCAAD4BAF6EC2DD5BBD3ABC7A1D9AA720E1C3AB53FA3310F2B64E09FE3DDF8822880F998AD8D5C99BF70FEDBA108610861086-1589363839854%7D'}]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "href"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "headers =index_header.copy()\n",
    "headers['Cookie'] = f'__jsluid_h={jsluid}; __jsl_clearance={jsl_clearance};JSESSIONID={JSESSIONID2}'\n",
    "detail = requests.get(url=href[0]['href'], headers = headers, proxies = proxy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "输出结果正确"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'北京百度网讯科技有限公司'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "etree.HTML(detail.text).xpath(\"//h1\")[0].text.strip()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 如果您看到这里，请给我一个star，谢谢，如有遗漏，请留言指正，感激！"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "blog",
   "language": "python",
   "name": "blog"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
